{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1ff5600c-6227-472b-878f-c5a4270f8e08",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y.shape= (4, 26, 26, 2)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input=(4,28,28,3)\n",
    "x=tf.random.normal(input)\n",
    "y=tf.keras.layers.Conv2D(2,3,strides=(1,1),padding='VALID',\n",
    "                         activation='relu',input_shape=input[1:])(x)\n",
    "print(\"y.shape=\",y.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cb3be606-74f6-401f-9229-e9ad8bfe9d59",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MaxPool(x).numpy()=\n",
      " [[[[3]\n",
      "   [4]]\n",
      "\n",
      "  [[4]\n",
      "   [3]]]]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input=tf.constant([[1,1,0,1],[3,-3,4,2],[2,0,1,3],[4,2,-1,0]])\n",
    "x=tf.reshape(input,[1,4,4,1])\n",
    "MaxPool=tf.keras.layers.MaxPool2D(pool_size=(2,2),strides=(2,2),padding='VALID')\n",
    "print(\"MaxPool(x).numpy()=\\n\",MaxPool(x).numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "03e6baaa-0136-47f4-abfc-4c6eb73f86bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AveragePooling(x).numpy()=\n",
      " [[[[0.5 ]\n",
      "   [1.75]]\n",
      "\n",
      "  [[2.  ]\n",
      "   [0.75]]]]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input=tf.constant([[1,1,0,1],[3,-3,4,2],[2,0,1,3],[4,2,-1,0]],dtype=tf.float32)\n",
    "x=tf.reshape(input,[1,4,4,1])\n",
    "AveragePooling=tf.keras.layers.AveragePooling2D(pool_size=(2,2),strides=(2,2),padding='VALID')\n",
    "print(\"AveragePooling(x).numpy()=\\n\",AveragePooling(x).numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "661a1d9c-11c8-4544-9d71-87f310e75178",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "inputs=\n",
      " [[ 0.  1.  2.  3.]\n",
      " [ 4.  5.  6.  7.]\n",
      " [ 8.  9. 10. 11.]\n",
      " [12. 13. 14. 15.]]\n",
      "outputs=\n",
      " [[ 0.  2.  0.  6.]\n",
      " [ 8. 10.  0. 14.]\n",
      " [ 0. 18. 20. 22.]\n",
      " [ 0. 26. 28.  0.]]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "tf.random.set_seed(0)\n",
    "layer=tf.keras.layers.Dropout(0.5,input_shape=(2,0))\n",
    "data=np.arange(16).reshape(4,4).astype(np.float32)\n",
    "outputs=layer(data,training=True)\n",
    "print(\"inputs=\\n\",data)\n",
    "print(\"outputs=\\n\",outputs.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a05bdf4-0965-4d1f-a493-4b436e352324",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
